<template>
	<view class="container">
		<view class="tabsbox">
			<u-tabs :list="tabs" :current="current" @click="tabsclick"></u-tabs>
		</view>
		<view class="mypubbox" v-if="current==0">
			<view class="switchbox">
				<uni-data-checkbox mode="tag" v-model="myPub_tabs" :localdata="myPub_tabslist"
					@change="myPub_tabsclick"></uni-data-checkbox>
			</view>

			<view class="goods-list">
				<view v-if="myPub_List.length>0" class="goods-list-item" v-for="(item,i) in myPub_List" :key="i">
					<view class="leftbox" @click="goodsClick(item)">
						<view class="imgbox">
							<image mode="scaleToFill" :src="item.image"></image>
						</view>
						<view class="content">
							<view class="mingcheng">商品名称：{{item.goodsname}}</view>
							<view>上架时间：{{item.date}}</view>
							<view v-if="item.mydealcode">交易时间：{{item.deal_date}}</view>
							<view v-if="item.mydealcode">交易密码：{{item.mydealcode}}</view>
							<view v-if="item.namebuy">交易对象：{{item.namebuy}}</view>
						</view>
					</view>
					<view v-if="myPub_showPop">
						<u-popup :show="myPub_showPop" mode="center" @close="myPub_close" :safeAreaInsetBottom="true"
							:safeAreaInsetTop="true" :overlay='true' :closeable="true" :bgColor="`#ffffff`"
							:round="'10px'" :closeOnClickOverlay="false">
							<view class="upopupbox">
								<text class="titlebox">完成交易</text>

								<text class="titlebox1">（三日未收到对方回复，则无需密码可直接申请完成）</text>

								<view class="codebox">
									<text>交易码:</text>
									<input type="text"  focus='true' placeholder="请输入对方交易码" v-model="myPub_dealcode" />
								</view>
								<u-button class="buttonbox" type="success" text="立即完成" @click="myPub_showPopwcClick(i)"
									customStyle="width: 400rpx" shape="circle" color="#ff0000">
								</u-button>
							</view>
						</u-popup>
					</view>
					<view class="rightbox" v-if="item.dealstate==='onsale'">
						<view class="top" v-if="item.jubao_state=='0'">已发布</view>
						<view class="top" v-if="item.jubao_state=='1'">被举报待审核</view>
						<view class="bottom" v-if="item.jubao_state=='0'">
							<u-button type="primary" @click.stop="xiajia(item)">下架</u-button>
							<!-- <u-button type="primary" @click.stop="bianji(item)">编辑</u-button> -->
						</view>
					</view>
					<view class="rightbox" v-if="item.dealstate==='ondeal'">
						<view class="top" v-if="item.jubao_state=='0'">交易中</view>
						<view class="top" v-if="item.jubao_state=='1'">被举报待审核</view>
						<view class="bottom" v-if="item.jubao_state=='0'">
							<u-button type="primary" @click.stop="myPub_saleqxClick(item)">取消</u-button>
							<u-button type="primary" @click.stop="myPub_salewcClick(item)">完成</u-button>
						</view>
					</view>
					<view class="rightbox" v-if="item.dealstate==='dealcomplete'">
						<view class="top">已完成</view>
					</view>
					<view class="rightbox" v-if="item.dealstate==='unsale'">
						<view class="top" v-if="item.jubao_state=='0'">已下架</view>
						<view class="top" v-if="item.jubao_state=='1'">被举报待审核</view>
						<view class="top" v-if="item.jubao_state=='2'">被举报已下架</view>
						<view class="bottom">
							<block v-if="item.jubao_state=='0'">

									<u-button type="primary" @click.stop="shangjia(item)">上架</u-button>
									<u-button type="primary" @click.stop="bianji(item)">编辑</u-button>

							</block>

							<u-button type="primary" @click.stop="shanchu(item)">删除</u-button>
						</view>


					</view>
				</view>
				<view v-if="myPub_List.length==0" class="shoproempty">
					<shopro-empty :image="mediaUrl + '/media/image/empty_goods.png'" tipText="暂无~"></shopro-empty>
				</view>

			</view>
		</view>

		<view class="myorderbox" v-if="current==1">
			<view class="switchbox">
				<uni-data-checkbox mode="tag" v-model="myOrder_tabs" :localdata="myOrder_tabslist"
					@change="myOrder_tabsclick"></uni-data-checkbox>
			</view>
			<view class="goods-list">
				<view v-if="myOrder_List.length>0" class="goods-list-item" v-for="(item,i) in myOrder_List" :key="i">
					<view class="leftbox" @click="goodsClick(item)">
						<view class="imgbox">
							<image mode="scaleToFill" :src="item.icon"></image>
						</view>
						<view class="content">
							<view class="mingcheng">商品名称：{{item.goodsname}}</view>
							<!-- <view>商品简介：{{item.goodsdetail}}</view> -->
							<view>上架时间：{{item.date}}</view>
							<view v-if="item.mydealcode">交易时间：{{item.deal_date}}</view>
							<view v-if="item.mydealcode">交易密码：{{item.mydealcode}}</view>
							<view v-if="item.namebuy">交易对象：{{item.namesale}}</view>
						</view>
					</view>
					<view v-if="myOrder_showPop">
						<u-popup :show="myOrder_showPop" mode="center" @close="myOrder_close"
							:safeAreaInsetBottom="true" :safeAreaInsetTop="true" :overlay='true' :closeable="true"
							:bgColor="`#ffffff`" :round="'10px'" :closeOnClickOverlay="false">
							<view class="upopupbox">
								<text class="titlebox">取消交易</text>
								<text class="titlebox1">（三日未收到回复，则无需密码可直接申请取消）</text>

								<view class="codebox">
									<text>交易码:</text>
									<input type="text"   :always-embed="true" auto-focus placeholder="请输入对方交易码" v-model="myOrder_dealcode" />
								</view>
								<u-button class="buttonbox" type="success" text="立即取消"
									@click="myOrder_showPopqxClick(item)" customStyle="width: 400rpx" shape="circle"
									color="#ff0000">
								</u-button>
							</view>
						</u-popup>
					</view>
					<!-- 交易业务逻辑 -->
					<view class="rightbox" v-if="item.dealstate==='ondeal'">
						<view class="top" v-if="item.jubao_state=='0'">交易中</view>
						<view class="top" v-if="item.jubao_state=='1'">举报待审核中</view>

						<view class="bottom" v-if="item.jubao_state=='0'">
							<u-button type="primary" @click.stop="myOrder_buyqxClick(item)">取消</u-button>
							<u-button type="primary" @click.stop="myOrder_buywcClick(item)">完成</u-button>
						</view>
					</view>
					<view class="rightbox" v-if="item.dealstate==='dealcomplete'">
						<view class="top">已取货</view>
					</view>
					<view class="rightbox" v-if="item.dealstate==='cancel'">
						<view class="top">已取消</view>
					</view>
				</view>
				<view v-if="myOrder_List.length==0" class="shoproempty">
					<shopro-empty :image="mediaUrl + '/media/image/empty_goods.png'" tipText="暂无~"></shopro-empty>
				</view>
			</view>
		</view>

		<view class="myorderbox" v-if="current==2">
			<view class="switchbox">
				<uni-data-checkbox mode="tag" v-model="tousu_tabs" :localdata="tousu_tabslist"
					@change="tousu_tabsclick"></uni-data-checkbox>
			</view>
			<view class="goods-list">
				<view v-if="tousu_List.length>0" class="goods-list-item" v-for="(item,i) in tousu_List" :key="i">
					<view class="leftbox" @click="goodsClick(item)">
						<view class="imgbox">
							<image mode="widthFix" :src="item.icon"></image>
						</view>
						<view class="content">
							<view class="mingcheng">商品名称：{{item.goodsname}}</view>
							<view>投诉原因：{{item.jubao_reson}}</view>
						</view>
					</view>
					<!-- 交易业务逻辑 -->
					<view class="rightbox" v-if="item.jubao_state=='1'">
						<view class="top">待审核</view>
						<view class="bottom">
							<u-button type="primary" @click.stop="checkyesClick(item)">通过</u-button>
							<u-button type="primary" @click.stop="checknoClick(item)">拒绝</u-button>
						</view>
					</view>
					<view class="rightbox" v-if="item.jubao_state=='2'">
						<view class="top">已审核</view>
					</view>

				</view>
				<view v-if="tousu_List.length==0" class="shoproempty">
					<shopro-empty :image="mediaUrl + '/media/image/empty_goods.png'" tipText="暂无~"></shopro-empty>
				</view>
			</view>
		</view>

		<view class="myorderbox" v-if="current==3">
			<view class="switchbox">
				<uni-data-checkbox mode="tag" v-model="jubao_tabs" :localdata="jubao_tabslist"
					@change="jubao_tabsclick"></uni-data-checkbox>
			</view>
			<view class="goods-list">
				<view v-if="jubao_List.length>0" class="goods-list-item" v-for="(item,i) in jubao_List" :key="i">
					<view class="leftbox" >
						<view class="imgbox">

							<swiper circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="1000"
								:duration="duration">
								<swiper-item v-for="(img,v) in item.imagelist" :key="v">
									<view @click="fangda(img)" class="xy">
										<image mode="widthFix" :src="img"></image>
									</view>
								</swiper-item>

							</swiper>
						</view>

						<view class="content">
							<view>举报人：{{item.tou_user}}</view>
							<view>被举报人：{{item.bei_user}}</view>
							<view>举报原因：{{item.reson}}</view>
							<view>举报时间：{{item.tou_date}}</view>

						</view>
					</view>
					<view class="rightbox" v-if="item.state=='0'">
						<view class="top">审核中</view>
						<view class="bottom">
							<u-button type="primary" @click.stop="tousuyes_check(item)">同意</u-button>
							<u-button type="primary" @click.stop="tousuno_check(item)">拒绝</u-button>
						</view>
					</view>
					<view class="rightbox" v-if="item.state=='1'">
						<view class="top">已审核</view>
					</view>

				</view>
				<view v-if="jubao_List.length==0" class="shoproempty">
					<shopro-empty :image="mediaUrl + '/media/image/empty_goods.png'" tipText="暂无~"></shopro-empty>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	var self;
	export default {
		data() {
			return {
				tabs: [{
					name: '我的发布'
				}, {
					name: '我的订单'
				}, ],
				current: 0,
				checker: false,
				mediaUrl: uni.$http.mediaUrl,
				userInfo: uni.getStorageSync('userInfo') || null,
				timeout: 1000,

				// my-publish-start
				myPub_tabs: 1,
				myPub_tabslist: [ {
					text: '已发布',
					value: 1
				}, {
					text: '交易中',
					value: 2
				}, {
					text: '已完成',
					value: 3
				}, {
					text: '已下架',
					value: 4
				}],
				myPub_List: [],
				myPubdealstate: 'onsale',
				myPubTimer: null,
				isbian: false,
				myPub_showPop: false,
				myPub_dealcode: '',
				myPub: {},
				// my-publish-end

				tousu_tabs: 0,
				tousu_tabslist: [{
					text: '待审核',
					value: 0
				}, {
					text: '已审核',
					value: 1
				}, ],
				tousu_List: [],

				jubao_tabs: 0,
				jubao_tabslist: [{
					text: '待审核',
					value: 0
				}, {
					text: '已同意',
					value: 1
				}, {
					text: '已驳回',
					value: 2
				}, ],
				jubao_List: [],


				// my-order-start
				myOrder_tabs: 1,
				myOrder_tabslist: [{
					text: '交易中',
					value: 1
				}, {
					text: '已完成',
					value: 2
				}],
				myOrder_List: [],
				myOrderdealstate: 'ondeal',
				myOrderTimer: null,

				myOrder_showPop: false,
				myOrder_dealcode: '',
				// my-order-end
			};
		},
		onLoad(e) {
			if (e.current) {
				this.current = e.current

				// console.log('onLoad11:')
			}
			this.getMyInfo()

		},
		onShow() {
			// console.log('onShow:',this.current)
			self = this

			if (this.current == 0) {
				// console.log('onShow11:')
				// clearInterval(this.myOrderTimer)
				switch (this.myPub_tabs) {
					case 1:
						this.myPub_OperateCenter('onsale');
						break
					case 2:
						this.myPub_OperateCenter('ondeal');
						break
					case 3:
						this.myPub_OperateCenter('dealcomplete');
						break
					case 4:
						this.myPub_OperateCenter('unsale');
						break
					default:
						this.myPub_OperateCenter('onsale');
						break
				}
			} else if (this.current == 1) {
				// console.log('onShow22:',this.current)
				// clearInterval(this.myPubTimer)
				switch (this.myOrder_tabs) {
					case 1:
						this.myOrder_OperateCenter('ondeal');
						break
					case 2:
						this.myOrder_OperateCenter('dealcomplete');
						break
					default:
						this.myOrder_OperateCenter('ondeal');
						break
				}
			} else if (this.current == 2) {
				// console.log('onShow22:',this.current)
				// clearInterval(this.myPubTimer)
				switch (this.tousu_tabs) {
					case 0:
						this.tousu_OperateCenter('1');
						break
					case 1:
						this.tousu_OperateCenter('2');
						break

				}
			} else if (this.current == 3) {
				// console.log('onShow22:',this.current)
				// clearInterval(this.myPubTimer)
				switch (this.jubao_tabs) {
					case 0:
						this.jubao_updateList(0);
						break
					case 1:
						this.jubao_updateList(1);
						break
					case 2:
						this.jubao_updateList(2);
						break
				}
			}
		},
		// onPullDownRefresh(e) {
		// 	console.log("上拉")

		// 	if (this.current == 0) {
		// 		// console.log('onShow11:')
		// 		// clearInterval(this.myOrderTimer)
		// 		switch (this.myPub_tabs) {
		// 			case 1:
		// 				this.myPub_OperateCenter('onsale');
		// 				break
		// 			case 2:
		// 				this.myPub_OperateCenter('ondeal');
		// 				break
		// 			case 3:
		// 				this.myPub_OperateCenter('dealcomplete');
		// 				break
		// 			case 4:
		// 				this.myPub_OperateCenter('unsale');
		// 				break
		// 			default:
		// 				this.myPub_OperateCenter('onsale');
		// 				break
		// 		}
		// 	} else if (this.current == 1) {
		// 		// console.log('onShow22:',this.current)
		// 		// clearInterval(this.myPubTimer)
		// 		switch (this.myOrder_tabs) {
		// 			case 1:
		// 				this.myOrder_OperateCenter('ondeal');
		// 				break
		// 			case 2:
		// 				this.myOrder_OperateCenter('dealcomplete');
		// 				break
		// 			default:
		// 				this.myOrder_OperateCenter('ondeal');
		// 				break
		// 		}
		// 	} else if (this.current == 2) {
		// 		// console.log('onShow22:',this.current)
		// 		// clearInterval(this.myPubTimer)
		// 		switch (this.tousu_tabs) {
		// 			case 0:
		// 				this.tousu_OperateCenter('1');
		// 				break
		// 			case 1:
		// 				this.tousu_OperateCenter('2');
		// 				break

		// 		}
		// 	} else if (this.current == 3) {
		// 		// console.log('onShow22:',this.current)
		// 		// clearInterval(this.myPubTimer)
		// 		switch (this.jubao_tabs) {
		// 			case 0:
		// 				this.jubao_updateList(0);
		// 				break
		// 			case 1:
		// 				this.jubao_updateList(1);
		// 				break
		// 			case 2:
		// 				this.jubao_updateList(2);
		// 				break
		// 		}
		// 	}
		// },
		onHide() {
			console.log('onHide:')
			// clearInterval(this.myPubTimer)
			// clearInterval(this.myOrderTimer)
		},
		onUnload() {
			console.log('onUnload:')
			// clearInterval(this.myPubTimer)
			// clearInterval(this.myOrderTimer)
		},
		methods: {
			async getMyInfo() {
				// console.log('getMyInfo'+this.userInfo.username)
				const userInfo = {
					username: this.userInfo.username,
				}
				const {
					data: res
				} = await uni.$http.post('getMyInfo/', userInfo)
				if (res.code == 200) {
					// console.log(res)
					this.checker=res.data.checker
					if (this.checker===true) {
						this.tabs = [{
							name: '我的发布'
						}, {
							name: '我的购买'
						}, {
							name: '投诉列表'
						}, {
							name: '举报列表'
						}]
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			},
			tabsclick(item) {
				this.current = item.index
				if (item.index == 0) {
					// console.log('000000000')
					// clearInterval(this.myOrderTimer)
					this.myPub_tabs = 1
					this.myPub_OperateCenter('onsale')
				} else if (item.index == 1) {
					// console.log('111111111')
					// clearInterval(this.myPubTimer)
					this.myOrder_tabs = 1
					this.myOrder_OperateCenter('ondeal')
				} else if (item.index == 2) {
					// console.log('111111111')
					// clearInterval(this.myPubTimer)
					this.tousu_tabs = 0
					this.tousu_OperateCenter(1)
				} else if (item.index == 3) {
					// console.log('111111111')
					// clearInterval(this.myPubTimer)
					this.jubao_tabs = 0
					this.jubao_updateList(0)
				}
			},
			bianji(item) {

				if (item.dealstate == 'onsale') {
					self.myPub_updateDealstate(item.goodsid, 'unsale')

				}
				uni.navigateTo({
					url: '/pages/home/btnpublish?goodsid=' + item.goodsid
				});

			},
			async shanchu(item) {
				uni.showModal({
						title: '提示',
						content: '确定删除吗？',
						success: async function(res) {
							if (res.confirm) {
								const postmsg = {
									goodsid: item.goodsid
								}
								const {
									data: res
								} = await uni.$http.post('shanchu/', postmsg)
								// console.log('myPub_update---',res)
								if (res.code == 200) {
									uni.showToast({
										title: res.msg,
										icon: 'success',
										duration: 1000
									});
									self.myPub_tabs = 4
									self.myPub_OperateCenter('unsale')
								}
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});



			},

			// my-publish-start
			myPub_tabsclick(item) {
				this.myPub_tabs = item.detail.value
				switch (item.detail.value) {
					case 1:
						this.myPub_OperateCenter('onsale', 'tabsclick1');
						break
					case 2:
						this.myPub_OperateCenter('ondeal', 'tabsclick2');
						break
					case 3:
						this.myPub_OperateCenter('dealcomplete', 'tabsclick3');
						break
					case 4:
						this.myPub_OperateCenter('unsale', 'tabsclick4');
						break
					default:
						this.myPub_OperateCenter('onsale', 'tabsclick1');
						break
				}
			},
			tousu_tabsclick(item) {
				// console.log(item.detail.value);
				this.tousu_tabs = item.detail.value;
				switch (item.detail.value) {
					case 0:
						this.tousu_OperateCenter(1);
						break;
					case 1:
						this.tousu_OperateCenter(2);
						break;
				}
			},
			jubao_tabsclick(item) {
				// console.log(item.detail.value);
				this.jubao_tabs = item.detail.value;
				switch (item.detail.value) {
					case 0:
						this.jubao_updateList(0);
						break;
					case 1:
						this.jubao_updateList(1);
						break;
					case 1:
						this.jubao_updateList(2);
						break;
				}
			},

			myPub_OperateCenter(dealstate) {
				self.myPub_updateList(dealstate)
			},
			myOrder_OperateCenter(dealstate) {
				self.myOrder_updateList(dealstate)
			},
			tousu_OperateCenter(dealstate) {
				self.tousu_updateList(dealstate);
			},
			async tousu_updateList(dealstate) {
				const postmsg = {

					check: dealstate
				}
				const {
					data: res
				} = await uni.$http.post('getCheckGoodsList/', postmsg)
				// console.log('myPub_update---',res)
				if (res.code == 200) {
					uni.stopPullDownRefresh();//上拉停止刷新

					self.tousu_List = []

					for (let i = 0; i < res.data.length; i++) {
						var obj = {}
						obj.id = res.data[i].id
						obj.goodsid = res.data[i].goodsid
						obj.goodsname = res.data[i].goodsname
						obj.goodsdetail = res.data[i].goodsdetail
						obj.imagelist = JSON.parse(res.data[i].imagelist);
						obj.icon = obj.imagelist[0]
						obj.dealstate = res.data[i].dealstate
						obj.date = res.data[i].date
						obj.phonesale = res.data[i].phonesale
						obj.phonebuy = res.data[i].phonebuy

						obj.jubao_reson = res.data[i].jubao_reson;
						obj.jubao_state = res.data[i].jubao_state;

						this.tousu_List.push(obj)
					}

				}
			},
			async jubao_updateList(dealstate) {
				const postmsg = {

					check: dealstate
				}
				const {
					data: res
				} = await uni.$http.post('gettousuList/', postmsg)
				// console.log('myPub_update---',res)
				if (res.code == 200) {
					uni.stopPullDownRefresh();//上拉停止刷新

					self.jubao_List = []

					for (let i = 0; i < res.data.length; i++) {
						var obj = {}
						obj.id = res.data[i].id
						obj.tou_user = res.data[i].tou_user
						obj.bei_user = res.data[i].bei_user
						obj.state = res.data[i].state
						obj.imagelist = JSON.parse(res.data[i].imagelist);
						obj.icon = obj.imagelist[0]
						obj.reson = res.data[i].reson
						obj.date = res.data[i].date
						obj.tou_date = res.data[i].tou_date

						this.jubao_List.push(obj)
					}

				}
			},

			// 投诉不成立
			async checknoClick(item) {
				const postmsg = {
					goodsid: item.goodsid,
					check: 0
				}
				const {
					data: res
				} = await uni.$http.post('goodsCheck/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						title: '成功',
						icon: 'success',
						duration: 2000
					});
					this.tousu_OperateCenter(1)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
				}
			},
			// 投诉成立
			async checkyesClick(item) {
				const postmsg = {
					goodsid: item.goodsid,
					check: 2
				}
				const {
					data: res
				} = await uni.$http.post('goodsCheck/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						title: '成功',
						icon: 'success',
						duration: 2000
					});
					this.tousu_OperateCenter(1)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
				}
			},

			// 举报不成立
			async tousuno_check(item) {
				const postmsg = {
					id: item.id,
					check: 2
				}
				const {
					data: res
				} = await uni.$http.post('tousuCheck/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						title: '成功',
						icon: 'success',
						duration: 2000
					});
					this.jubao_updateList(0)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
				}
			},
			// 投诉成立
			async tousuyes_check(item) {
				const postmsg = {
					id: item.id,
					check: 1
				}
				const {
					data: res
				} = await uni.$http.post('tousuCheck/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						title: '成功',
						icon: 'success',
						duration: 2000
					});
					this.jubao_updateList(0)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
				}
			},

			async myPub_updateList(dealstate) {
				const postmsg = {
					username: this.userInfo.username,
					dealstate: dealstate
				}
				const {
					data: res
				} = await uni.$http.post('getMyPubList/', postmsg)
				// console.log('myPub_update---',res)
				if (res.code == 200) {
					// uni.stopPullDownRefresh();//上拉停止刷新

					self.myPub_List = []

					for (let i = 0; i < res.data.length; i++) {
						var obj = {}
						obj.id = res.data[i].id
						obj.goodsid = res.data[i].goodsid
						obj.goodsname = res.data[i].goodsname
						obj.goodsdetail = res.data[i].goodsdetail
						obj.imagelist = JSON.parse(res.data[i].imagelist);
						obj.image = obj.imagelist[0]
						obj.dealstate = res.data[i].dealstate
						obj.date = res.data[i].date
						obj.deal_date = res.data[i].deal_date
						obj.phonesale = res.data[i].phonesale
						obj.phonebuy = res.data[i].phonebuy

						obj.jubao_reson = res.data[i].jubao_reson;
						obj.jubao_state = res.data[i].jubao_state;
						let str = res.data[i].dealcode
						if (str != null) {
							obj.mydealcode = str.substring(0, 4)
							obj.yourdealcode = str.substring(4, str.length)
						}
						this.myPub_List.push(obj)
					}

				}
			},

			goodsClick(item) {
				uni.navigateTo({
					url: '/pages/home/goodsdetail?goodsid=' + item.goodsid
				})
			},
			async myPub_updateDealstate(goodsid, dealstate) {
				const postmsg = {
					goodsid: goodsid,
					dealstate: dealstate
				}
				const {
					data: res
				} = await uni.$http.post('updateMyPubLish/', postmsg)
				if (res.code == 200) {
					return true
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
					return false
				}
			},
			xiajia(item) {
				self = this
				self.myPub_updateDealstate(item.goodsid, 'unsale').then((res) => {
					if (res) {
						self.myPub_tabs = 4
						self.myPub_OperateCenter('unsale')
					}else{
						setTimeout(function() {

							uni.reLaunch({
								url: '/pages/mine/dealinfo?current=' + 0
							});
						}, 1000);
					}
				})

			},
			shangjia(item) {
				self = this

				self.myPub_updateDealstate(item.goodsid, 'onsale')
					.then(() => {
						self.myPub_tabs = 1
						self.myPub_OperateCenter('onsale')
					})


			},
			myPub_saleqxClick(item) {
				uni.showModal({
					title: '提示',
					content: '确定取消吗？',
					success: async function(res) {
						if (res.confirm) {
							const postmsg = {
								goodsid: item.goodsid,
								dealstate: 'saleqx'
							}
							const {
								data: res
							} = await uni.$http.post('updateMyPubLish/', postmsg)
							if (res.code == 200) {
								uni.showToast({
									icon: 'success',
									title: '订单取消成功',
									duration: 1000
								})
								self.myPub_tabs = 1
								self.myPub_showPop = false
								self.myPub_OperateCenter('onsale')
							} else {
								uni.showToast({
									icon: 'none',
									title: res.msg,
									duration: 1000
								})
								self.myPub_tabs = 2
								self.myPub_OperateCenter('ondeal')

								// console.log(res.msg);
							}

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			fangda(item) {
			      console.log(item)
			      // var imgUrl = e;
			      wx.previewImage({
			        urls: [item], //需要预览的图片http链接列表，注意是数组
			        current: '', // 当前显示图片的http链接，默认是第一个
			        success: function (res) { },
			        fail: function (res) { },
			        complete: function (res) { },
			      })
			    },

			myOrder_buyqxClick(item) {
				this.myPub = item
				this.myOrder_dealcode = ''
				self.myOrder_showPop = true
			},
			myPub_salewcClick(item) {
				this.myPub = item
				console.log(this.myPub)

				self.myPub_dealcode = ''
				self.myPub_showPop = true
			},
			myPub_close() {

				self.myPub_showPop = false
			},
			myOrder_close() {
				self.myOrder_showPop = false
			},
			async myPub_showPopwcClick(item) {
				item = this.myPub
				console.log(item)
				// console.log(this.santian(item))
				if (this.santian(item) <= 3) {
					if (item.yourdealcode !== this.myPub_dealcode) {

						uni.showToast({
							icon: 'error',
							title: '交易码错误'
						})
						return
					}

				}
				const postmsg = {
					goodsid: item.goodsid,
					dealstate: 'salewc'
				}
				const {
					data: res
				} = await uni.$http.post('updateMyPubLish/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						icon: 'success',
						title: '交易完成',
						duration: 1000
					})
					self.myPub_tabs = 3
					self.myPub_dealcode = ''
					self.myPub_showPop = false
					self.myPub_OperateCenter('dealcomplete')
				} else {
					uni.showToast({
						icon: 'error',
						title: res.msg,
						duration: 1000
					})
					self.myPub_tabs = 2
					self.myPub_dealcode = ''
					self.myPub_showPop = false
					self.myPub_OperateCenter('ondeal')

				}

			},

			async myOrder_showPopqxClick(item) {
				item = this.myPub
				console.log(item)
				// console.log(item)
				if (this.santian(item) <= 3) {
					if (item.yourdealcode !== this.myOrder_dealcode) {

						uni.showToast({
							icon: 'error',
							title: '交易码错误'
						})
						return
					}

				}
				const postmsg = {
					goodsid: item.goodsid,
					dealstate: 'buyqx'
				}
				const {
					data: res
				} = await uni.$http.post('updateMyPubLish/', postmsg)
				if (res.code == 200) {
					uni.showToast({
						icon: 'success',
						title: '订单取消成功',
						duration: 1000
					})
					self.myOrder_tabs = 1
					this.myOrder_dealcode = ''
					self.myOrder_showPop = false
					self.myOrder_OperateCenter('ondeal')
				} else {
					uni.showToast({
						icon: 'error',
						title: res.msg,
						duration: 1000
					})
					this.myOrder_dealcode = ''
					self.myOrder_showPop = false
					self.myOrder_tabs = 1
					self.myOrder_OperateCenter('ondeal')
				}
			},

			santian(item) {
				// 判断交易是否超过了三天
				var day = parseInt((new Date() - new Date(item.deal_date)) / (1000 * 60 * 60 * 24));
				return day;
			},

			myOrder_tabsclick(item) {
				this.myOrder_tabs = item.detail.value
				switch (item.detail.value) {
					case 1:
						this.myOrder_OperateCenter('ondeal');
						break
					case 2:
						this.myOrder_OperateCenter('dealcomplete');
						break
					default:
						this.myOrder_OperateCenter('ondeal');
						break
				}
			},

			async myOrder_updateList(dealstate) {
				const postmsg = {
					username: this.userInfo.username,
					dealstate: dealstate,
				}
				// console.log('updateOrder--',postmsg)
				const {
					data: res
				} = await uni.$http.post('getMyOrder/', postmsg)
				if (res.code == 200) {
					uni.stopPullDownRefresh();//上拉停止刷新

					self.myOrder_List = []
					for (let i = 0; i < res.data.length; i++) {
						var obj = {}
						obj.id = res.data[i].id
						obj.goodsid = res.data[i].goodsid
						obj.goodsname = res.data[i].goodsname
						obj.goodsdetail = res.data[i].goodsdetail
						obj.icon = (JSON.parse(res.data[i].imagelist))[0];
						obj.phonesale = res.data[i].phonesale
						obj.phonebuy = res.data[i].phonebuy
						// obj.namesale = res.orders[i].namesale
						// obj.namebuy = res.orders[i].namebuy
						obj.dealstate = res.data[i].dealstate
						obj.date = res.data[i].date
						obj.deal_date = res.data[i].deal_date
						obj.phonesale = res.data[i].phonesale
						obj.phonebuy = res.data[i].phonebuy
						obj.jubao_state = res.data[i].jubao_state
						obj.jubao_reson = res.data[i].jubao_reson
						// obj.namesale = res.orders[i].namesale
						// obj.namebuy = res.orders[i].namebuy
						let str = res.data[i].dealcode
						if (str != null) {
							obj.yourdealcode = str.substring(0, 4)
							obj.mydealcode = str.substring(4, str.length)
						}
						this.myOrder_List.push(obj)
					}
				}

			},

			myOrder_goodsClick(item) {
				uni.navigateTo({
					url: '/pages/home/goodsdetail?goodsid=' + item.goodsid
				})
			},

			myOrder_buywcClick(item) {
				// item = this.myPub
				console.log(item)

				self = this
				uni.showModal({
					title: '提示',
					content: '确定完成吗？',
					success: async function(res) {
						if (res.confirm) {
							const postmsg = {
								goodsid: item.goodsid,
								dealstate: 'buywc'
							}
							const {
								data: res
							} = await uni.$http.post('updateMyPubLish/', postmsg)
							if (res.code == 200) {
								uni.showToast({
									icon: 'success',
									title: '交易完成',
									duration: 1000
								})
								self.myOrder_tabs = 2
								self.myOrder_OperateCenter('dealcomplete')
							} else {
								uni.showToast({
									icon: 'error',
									title: res.msg,
									duration: 1000
								})
								self.myOrder_tabs = 1
								self.myOrder_OperateCenter('ondeal')
							}
						} else if (res.cancel) {
							console.log('用户点击完成');
						}
					}
				});
			}


		}
	}
</script>

<style lang="scss">
	page,
	.container {
		background-color: #f2f2f2;

	}
	.mingcheng{
		font-size: 30rpx;
	}

	.tabsbox {
		// background-color: #0000ff;
		// height: 40px;
		// border: 1px;
		border-bottom: 4px solid #eaeaea;
	}


	.imgbox {
		width: 200rpx;
		height: 130px;
		border-radius: 1px;
	}

	.titlebox1 {
		// margin-top: 30px;
		// font-size: 13px;
		color: rgb(236, 22, 22);
		// display: flex;
		// justify-content: center;
		font-size: 24rpx;
		box-sizing: border-box;
	}

	.mypubbox {
		height: 40px;
		width: 100%;
		margin-top: 10px;
		// margin-bottom: 10px;

		.switchbox {
			display: flex;
			justify-content: start;
			width: 100%;
			// background-color: #ff0000;
			padding: 0 10px;
		}

		.goods-list {
			width: 100%;
			margin-top: 15px;

			// background-color: #ff0000;
			.goods-list-item {
				// background-color: aquamarine;
				width: 100%;
				display: flex;
				justify-content: space-between;
				padding: 5px 4px;
				box-sizing: border-box;
				border-top: 2px solid #eaeaea;
				border-bottom: 2px solid #eaeaea;
				border-left: 2px solid #eaeaea;

				.leftbox {
					// background-color: #00ff00;
					display: flex;
					// align-items: center;

					.imgbox {
						image {
							width: 100%;
							height: 130px;
							border-radius: 1px;
						}

					}

					.content {
						margin-left: 5px;
						font-size: 12px;

						:nth-child(1) {
							font-weight: bold;
						}
					}
				}

				.rightbox {
					max-width: 80px;
					min-width: 80px;
					// background-color: #0000ff;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.top {
						font-weight: bold;
						font-size: 12px;
						color: #e34e4e;
					}

					.bottom {
						font-size: 12px;
						color: #fff;
						// background-color: #169bd5;
						border-radius: 5px;
						text-align: center;
						display: flex;
						flex-direction: column;

						:nth-child(1) {
							height: 26px;
						}

						:nth-child(2) {
							height: 26px;
							margin-top: 6px;
						}
						:nth-child(3) {
							height: 26px;
							margin-top: 6px;
						}
					}
				}
			}

			.shoproempty {
				// background-color: #ff0000;
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.upopupbox {
			width: 600rpx;
			padding-bottom: 50rpx;
			margin-top: 0px;

			.titlebox {
				font-size: 18px;
				display: flex;
				justify-content: center;
			}

			.codebox {
				margin-top: 40rpx;
				margin-bottom: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #545454;

				input {
					background-color: lightgray;
					width: 160px;
					padding: 4px;
					margin-left: 10px;
				}
			}


			.buttonbox {
				margin-bottom: 10rpx;
				background: -webkit-linear-gradIEnt(left,#6C64D0,#8481C8)!important;
			}
		}
	}

	.myorderbox {
		height: 40px;
		width: 100%;
		margin-top: 20px;

		.switchbox {
			display: flex;
			justify-content: start;
			width: 100%;
			// background-color: #ff0000;
			padding: 0 10px;
		}

		.goods-list {
			// background-color: #ff0000;
			height: 100%;

			.goods-list-item {
				// background-color: aquamarine;
				width: 100%;
				display: flex;
				justify-content: space-between;
				padding: 5px 4px;
				box-sizing: border-box;
				border-top: 2px solid #eaeaea;
				border-bottom: 2px solid #eaeaea;
				border-left: 2px solid #eaeaea;

				.leftbox {
					// background-color: #00ff00;
					display: flex;

					.imgbox {
						image {
							width: 100%;
							height: 100%;
							border-radius: 1px;
						}

						swiper {
							height: 120px;
							// width: 100%;
						}
					}

					.content {
						margin-left: 5px;
						font-size: 12px;

						:nth-child(1) {
							font-weight: bold;
						}
					}
				}

				.rightbox {
					max-width: 80px;
					min-width: 80px;
					// background-color: #0000ff;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.top {
						font-weight: bold;
						font-size: 12px;
						color: #e34e4e;
					}

					.bottom {
						font-size: 12px;
						color: #fff;
						// background-color: #169bd5;
						border-radius: 5px;
						text-align: center;
						display: flex;
						flex-direction: column;

						:nth-child(1) {
							height: 26px;
						}

						:nth-child(2) {
							height: 26px;
							margin-top: 6px;
						}

						:nth-child(3) {
							height: 26px;
							margin-top: 6px;
						}
					}
				}
			}

			.shoproempty {
				// background-color: #ff0000;
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.upopupbox {
			width: 600rpx;
			padding-bottom: 50rpx;
			margin-top: 0px;
			padding: 30rpx 30rpx;
			box-sizing: border-box;

			.titlebox {
				font-size: 18px;
				display: flex;
				justify-content: center;
			}

			.codebox {
				margin-top: 40rpx;
				margin-bottom: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #545454;

				input {
					background-color: #lightgray;
					width: 160px;
					padding: 4px;
					margin-left: 10px;
				}
			}

			.buttonbox {
				margin-bottom: 10rpx;
				background: -webkit-linear-gradIEnt(left,#6C64D0,#8481C8)!important;
			}
		}
	}
</style>
